package com.product.android.business.service;

import com.common.android.utils.ToastUtils;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

public class BaseMsgBroadCastReceiver extends BroadcastReceiver {
	
//	private static final String TAG = "BaseMsgBroadCastReceiver";
	private ReceiveCallback mCallBack;
	private Context mContext;
	private Bundle bundle;
	
	public BaseMsgBroadCastReceiver(ReceiveCallback callBack, Context context){
		mContext = context;
		mCallBack = callBack;
	}
	
	@Override
	public void onReceive(Context context, Intent intent) {
		
		bundle = intent.getExtras();
		int receiveCmd=0;
		if(bundle.containsKey("cmd")){
			receiveCmd = intent.getIntExtra("cmd",0);
		}
//		Log.v("debug","收到广播命令："+receiveCmd);
		switch (receiveCmd) {
		case BroadcastCMD.CMD_89:
			if(mCallBack != null)
				mCallBack.handler_CMD_89();
			break;
		case BroadcastCMD.CMD_SHOWLEFT:// 滑动到左边menu页
			if(mCallBack != null)
				mCallBack.handler_CMD_SHOWLEFT();
			break;
		case BroadcastCMD.CMD_SHOWRIGHT:// 滑动到右边menu页
			if(mCallBack != null)
				mCallBack.handler_CMD_SHOWRIGHT();
			break;
//		case IMSConfiguration.CMD_506:
//			if(mCallBack != null)
//				mCallBack.handler_CMD_506();
//			break;
//		case IMSConfiguration.CMD_507:
//			if(mCallBack != null)
//				mCallBack.handler_CMD_507();
//			break;
		case BroadcastCMD.CMD_33:
			if(mCallBack != null)
				mCallBack.handler_CMD_33();
			break;
		case BroadcastCMD.CMD_36864: // 通知上线成功广播
			if(mCallBack != null)
				mCallBack.handler_CMD_36864();
			break;
		case BroadcastCMD.CMD_119: // 通知上线成功广播
			if(mCallBack != null)
				mCallBack.handler_CMD_119();
			break;
		case BroadcastCMD.CMD_51://好友状态改变
			if(mCallBack != null)
				mCallBack.handler_CMD_51();
			break;
		case BroadcastCMD.CMD_53://好友状态或登陆点改变
			if(mCallBack != null)
				mCallBack.handler_CMD_53();
			break;
		case BroadcastCMD.OAPCMD_5502: // 票据过期
			if(mCallBack != null)
				mCallBack.handler_CMD_5502();
			break;
		case BroadcastCMD.CMD_39://取在线列表返回
			if(mCallBack != null)
				mCallBack.handler_CMD_39();
			break;
//		case IMSConfiguration.CMD_399://正在重连，通知转
//		case IMSConfiguration.CMD_400://发送掉线失败广播信息
//		case IMSConfiguration.CMD_120:
		case BroadcastCMD.CMD_16://自已状态变更
			if(mCallBack != null)
				mCallBack.handler_CMD_16();
			break;
//		case IMSConfiguration.CMD_9: //离线
//			if(mCallBack != null)
//				mCallBack.handler_CMD_9();
//			break;
		case BroadcastCMD.CMD_12000:
			if(mCallBack != null){
				if(intent.hasExtra("url")){
					mCallBack.handler_CMD_12000(intent.getStringExtra("url"));
				}
				else{
					mCallBack.handler_CMD_12000();
				}
			}
			break;
//		case IMSConfiguration.CMD_505: //网络异常处理
//			if(mCallBack != null)
//				mCallBack.handler_CMD_505();
//			break;
//		case IMSConfiguration.CMD_402: //网络异常	
//			if(mCallBack != null)
//				mCallBack.handler_CMD_402(bundle);
//			break;
//		case IMSConfiguration.CMD_403:	//向服务器写报文失败 IO异常
//			if(mCallBack != null)
//				mCallBack.handler_CMD_403();
//			break;
//		case IMSConfiguration.CMD_404://等服务器命令超时反馈广播信息
//			if(mCallBack != null)
//				mCallBack.handler_CMD_404();
//			break;
//		case IMSConfiguration.CMD_405://消息发送失败
//			if(mCallBack != null)
//				mCallBack.handler_CMD_405();
//			break;
		case BroadcastCMD.CMD_31:
			if(mCallBack != null)
				mCallBack.handler_CMD_31();  //还是全部通知，31会用的很少了
			break;
		case BroadcastCMD.CMD_30010:  //用户个性签名变更
			if(mCallBack != null)
				mCallBack.handler_CMD_30010();
			break;
		case BroadcastCMD.CMD_30011:  //用户头像变更
			if(mCallBack != null)
				mCallBack.handler_CMD_30011();
			break;
		case BroadcastCMD.CMD_REMOVE_GROUP:
			if(mCallBack != null)
				mCallBack.handler_CMD_RemoveGroup(bundle);
			break;
		case BroadcastCMD.CMD_49156://ECP
			if(mCallBack != null)
				mCallBack.handler_CMD_49156(bundle);
			break;
		case BroadcastCMD.CMD_SUGGEST:
			if(mCallBack != null)
				mCallBack.handler_CMD_Suggest();
			break;
		case BroadcastCMD.CMD_85674://通讯录变更
			if(mCallBack != null)
				mCallBack.handler_CMD_85674();
		case BroadcastCMD.GROUP_SYSMSG_TYPE_GROUP_INFO_CHANGED:	
			if(mCallBack != null)
				mCallBack.handler_CMD_GROUP_SYSMSG_TYPE_GROUP_INFO_CHANGED(bundle);
			
			break;
		case BroadcastCMD.CMD_GETAPPINFO:  //取应用广播
			if(mCallBack != null)
				mCallBack.handler_CMD_GETAPPINFO();
			
			break;
		case 2000:
			if(bundle.containsKey("msgData")){
				ToastUtils.display(mContext, bundle.getString("msgData"));
			}
			break;
		case 635:
			if(mCallBack != null)
				mCallBack.handler_CMD_635();
			break;
		case BroadcastCMD.CMD_x20000:
			if(mCallBack != null)
				mCallBack.handler_CMD_x20000();  // 好友分组
			break;
		case BroadcastCMD.CMD_x20002:
			if(mCallBack != null)
				mCallBack.handler_CMD_x20002();  // 应用列表
			break;
		case BroadcastCMD.CMD_x20003:
			if(mCallBack != null)
				mCallBack.handler_CMD_x20003();  // 好友增删及列表
			break;
		case BroadcastCMD.CMD_x20004:
			if(mCallBack != null)
				mCallBack.handler_CMD_x20004();  // 群组增删及列表
			break;
		case BroadcastCMD.CMD_x20005:	//加载组织结束
			if(mCallBack != null)
				mCallBack.handler_CMD_x20005();  //631改为组织树同步
			break;
		}
	}
}
